'''
Description: 
Author: Zilu
Date: 2021-11-15 10:31:49
Version: 
LastEditTime: 2021-11-15 11:14:56
LastEditors: Zilu
'''

# 海龟绘图
from turtle import *

# 设置笔刷宽度
width(4)

# 前进
forward(200)
# 右转90度
right(90)

# 笔刷颜色
pencolor('red')
forward(200)
right(90)

pencolor('blue')
forward(200)
right(90)

pencolor('green')
forward(200)
right(90)

# 调用done()使得窗口等待被关闭，否则将立刻关闭窗口:
done()

# turtle的更多说明见官网https://docs.python.org/3.3/library/turtle.html#turtle-methods
def drawStar(x, y):
    pu()
    goto(x, y)
    pd()
    # set heading: 0
    seth(0)
    for i in range(5):
        fd(40)
        rt(144)
    
for x in range(0, 250, 50):
    drawStar(x, 0)

done()

# 分型树
colormode(255) # RGB颜色模式
lt(90)

lv = 14
l = 120
s = 45

width(lv)

# 初始化颜色
r, g, b = (0, 0, 0)
pencolor(r, g, b)

penup()
bk(l)
pendown()
fd(l)

def drawTree(l, level):
    global r, g, b
    # save the current pen width
    w = width()

    width(w * 3.0 / 4.0)
    r += 1
    g += 2
    b += 3
    pencolor((r % 255) / 255, (g % 255) / 255, (b % 255) / 255)

    l = l * 3.0 / 4.0
    lt(s)
    fd(l)

    if level < lv:
        drawTree(l, level + 1)
    bk(l)
    rt(2 * s)
    fd(l)

    if level < lv:
        drawTree(l, level + 1)

    bk(l)
    lt(s)

    # restore the previous pen width
    width(w)

speed('fastest')

drawTree(l, 4)

done()



